import java.util.TimeZoneimport net.fortuna.ical4j.model.Propertyimport net.fortuna.ical4j.model.TimeZoneRegistryFactoryimport net.fortuna.ical4j.model.property.Urlimport net.fortuna.ical4j.util.UidGeneratorimport net.fortuna.ical4j.util.SimpleHostInfoimport net.fortuna.ical4j.model.component.VFreeBusyimport net.fortuna.ical4j.data.CalendarBuilderimport net.fortuna.ical4j.model.property.DtStampimport net.fortuna.ical4j.model.DateTimeimport net.fortuna.ical4j.model.ContentBuilderdef calUrl = request.getParameter('u')def start = request.getParameter('start')def end = request.getParameter('end')def dur = request.getParameter('dur')def tzId = request.getParameter('tz')//def gcalUrl = 'http://www.google.com/calendar/ical/benfortuna@gmail.com/public/basic.ics'def calendar = new CalendarBuilder().build(new URL(calUrl).openStream())def uidGenerator = new UidGenerator(new SimpleHostInfo('fburl.org'), '1')//def tzRegistry = TimeZoneRegistryFactory.instance.createRegistry();
def builder = new ContentBuilder()def defaultTz = TimeZone.default//change the local timezone if specified..if (tzId) {//    def tz = tzRegistry.getTimeZone(tzId)    def tz = TimeZone.getTimeZone(tzId)    TimeZone.default = tz}def busytime = new VFreeBusy(builder.vfreebusy() {    dtstart(start, parameters: parameters() {        value('DATE')})    dtend(end, parameters: parameters() {        value('DATE')})            if (dur) {        duration(dur)    }}, calendar.components)busytime.properties.add(uidGenerator.generateUid())//busytime.properties.add(new Url(request.getRequestURL().append(request.getQueryString()).toString()))def freeBusy = builder.calendar() {    prodid('-//fburl.org//NONSGML freebusy 1.0//EN')    version('2.0')//    attendee(user)    vfreebusy(busytime)}//freeBusy.components.addAll(gcalCalendar.getComponents('VFREEBUSY'))TimeZone.default = defaultTzresponse.contentType = 'text/calendar'out.println(freeBusy)